window.onload = () => {
  let itemsDOM = document.getElementById("items");
  let submitBtn = document.getElementById('submitBtn');
  submitBtn.onclick = (e) => {
    let item = document.getElementById('item');
    fetch('http://192.168.59.144:8080/todo', {method: 'POST', body: `item=${item.value}`})
    .then(res => { 
      res.text().then( txt =>{
        let items = JSON.parse(txt).data;
        itemsDOM.innerHTML = items.map(item => `<li>${items}</li>`)
      })
    });
  }
  fetch('http://192.168.59.144:8080/todo').then(res =>
    { 
      res.text().then(txt => {
        let items = JSON.parse(txt).data;
        itemsDOM.innerHTML = items.map(item => '<li>'+item+'</li>').join('\n');
      });
    });
}

